#include <iostream>
#include <fstream>

using namespace std;

//二进制方式读文件主要利用流对象调用成员函数read
//函数原型：istream& read(char *buffer,int len);
//参数解释：字符指针buffer指向内存中一段存储空间。len是读写的字节数
class Person {
public:
    char name[64];//姓名
    int age;//年龄
};

void test1() {
    ifstream ifs;
    ifs.open("E:\\C++Study\\CPPStudy\\day19-file\\person.txt", ios::out | ios::binary);
    if (!ifs.is_open()) {
        cout << "文件打开失败" << endl;
        return;
    } else {
        Person p;
        ifs.read((char *) &p, sizeof(p));
        cout << "p:name=" << p.name << ",age=" << p.age << endl;
    }
    ifs.close();
}

int main() {
    test1();
    return 0;
}